package com.bookmarket.service.impl;

import com.bookmarket.dao.LQMainMapper;
import com.bookmarket.entity.*;
import com.bookmarket.service.LQMainService;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.Date;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Service("mainService")
public class LQMainServiceImpl implements LQMainService {
    @Resource
    private LQMainMapper mainMapper;

    @Override
    public List<Stype> queryAllSType() {
        return mainMapper.queryAllSType();
    }

    @Override
    public void addClick(int id) {
        mainMapper.addClick(id);
    }

    @Override
    public int queryShop(int customId, int bookId) {
        return mainMapper.queryShop(customId,bookId);
    }

    @Override
    public int updateBookNumToShop(Book book, int customID, int number) {
        Map map = new HashMap();
        map.put("bookID",book.getId());
        map.put("bookNum",number);
        map.put("customID",customID);
        return mainMapper.updateBookNumToShop(map);
    }

    @Override
    public List<Book> recommend() {
        Page page = PageHelper.startPage(0,6);
        return mainMapper.recommend();
    }

    @Override
    public int queryBtypeByBookId(int id) {
        return mainMapper.queryBtypeByBookId(id);
    }

    @Override
    public List<Active> queryAllActive() {
        return mainMapper.queryAllActive();
    }

    @Override
    public List<Book> enjoy() {
        return mainMapper.enjoy();
    }

    @Override
    public List<Book> queryBook(Book book) {
        Page page = PageHelper.startPage(0,12);
        List<Book> list = mainMapper.queryBook(book);
        return list;
    }

    @Override
    public Book queryOneBook(int id) {
        return mainMapper.queryOneBook(id);
    }

    @Override
    public List<Mess> queryBookMess(int id) {
        return mainMapper.queryBookMess(id);
    }

    @Override
    public int addBookToShop(Book book, int customID, int number) {
        Map map = new HashMap();
        map.put("bookID",book.getId());
        map.put("bookNum",number);
        map.put("customID",customID);
        map.put("bookName",book.getName());
        map.put("bookPrice",book.getPrice());
        map.put("bookPicture",book.getPicture());
        map.put("createTime",new Date());
        return mainMapper.addBookToShop(map);
    }

    @Override
    public List<Stype> querySType() {
        return mainMapper.querySType();
    }

    public void setMainMapper(LQMainMapper mainMapper) {
        this.mainMapper = mainMapper;
    }
}
